import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { AtIcon, AtButton } from 'taro-ui'
import './myHealthRecordsDetails.scss'
import right from '../../img/right.png'
import app from '../../main'

export default class MyHealthRecordsDetails extends Component {

    config = {
        navigationBarTitleText: '健康档案'
    }
    constructor() {
        super(...arguments)
        this.state = {
            // 患者数据
            patientInfo: [
                {
                    "id": "1",
                    "patient_id": "1123",
                    "patient_name": "掴星星",
                    "sex": "男",
                    "age": "21",
                    "juwangshi": "无眼外伤史，糖尿病，无戴镜，双眼白内障，无传染病史，头孢类过敏"
                }
            ],
            // 病历记录
            binglijilu: [
                {
                    "id": "1",
                    "doc_name": "终南山",
                    "hospite": "中山验卡",
                    "content": "双眼渐进性视力下降2年，诊断为双眼老年核性白内障",
                    "code": "324144156",
                    "create_at": "2012-1-12"
                },
                {
                    "id": "1",
                    "doc_name": "李天一",
                    "hospite": "中山验卡",
                    "content": "双眼渐进性视力下降2年，诊断为双眼老年核性白内障",
                    "code": "324144156",
                    "create_at": "2012-1-12"
                }
            ]
        }
    }
    //跳转患者信息
    handleClick(patient_id) {
        // console.log('a',patient_id)
        app.navigateTo('../patientInformation/patientInformation'+'?id='+patient_id)
    }
    handleClickDetailedPatientHistory() {
        // app.navigateTo('../detailedPatientHistory/detailedPatientHistory');
        app.navigateTo('../caseDetail/caseDetail')
    }
    

offect = 0
length = 0
total = 0
isFinlsh = false

    //上拉加载
    onReachBottom() {
        if ((this.offect + this.length) < this.total) {
            app.toast('正在加载----')
            this.offect = this.offect + this.length;
            this.isFinlsh = false;
            //调用接口
            this.getDate2();
        } else {
            app.toast('没有更多数据了咯')
            this.isFinlsh = true;
        }
    }
    // 数据获取
    getDate1() {
        let me = this
        let data = { token: "", offect:this.offect, length: this.length,id:this.$router.params.id }
        // 获取患者信息
        app.get('json/liangguan/myHealthRecordsDetails.json', data, function (res) {
            me.setState({
                patientInfo: res.data.result.list
            })
        })

    }
    // 获取病历记录
    getDate2(){
        let me = this
        let data = { token: "0", offect: 0, length: 0,id:this.$router.params.id }
        let dataArray=[]
        app.get('json/liangguan/myHealthRecordsDetailsBingli.json', data, function (res) {
            dataArray = dataArray.concat(res.data.result.list)
            me.total = res.data.result.total
            me.setState({
                binglijilu: dataArray
            })
        })
    }

    componentDidMount() {
        this.getDate1()
        this.getDate2()
    }

    render() {
        let patientInfo = this.state.patientInfo[0]
        // 病历记录数据
        let binglijilu = this.state.binglijilu.map((item) => {
            return <View className='centerText' onClick={this.handleClickDetailedPatientHistory.bind(this,item.id)}>
                        <View><Text className='name'>{item.doc_name}</Text> {item.hospite}</View>
                        <View className='bottonIcon'>
                            <Text>{item.content}</Text>
                        </View>
                        <View className='bottonIcon'>
                            <AtIcon value='bullet-list' size='small' /><Text className='t1'>{item.code}</Text>
                            <AtIcon value='calendar' size='small' /><Text className='t1'>{item.create_at}</Text>
                        </View>
                    </View>
        })
        return (
            <View>
                {/* 患者信息 */}
                <View className='top'>
                    <View className='topTitle' onClick={()=>this.handleClick(patientInfo.id)}>
                        <View>
                            <Text className='name'> {patientInfo[0].patient_name}</Text> {patientInfo[0].sex} ：{patientInfo.age}岁
                        </View>
                        <View><Image className='top-image' src={right} /></View>
                    </View>
                    <View className='topText'>
                        <View className='name'>既往史</View>
                        <View >{patientInfo[0].juwangshi}</View>
                    </View>
                </View>
                {/* 病历记录 */}
                <View className='center'>
                    <View className='title2'>
                        <Text>病历记录</Text>
                    </View>
                    {binglijilu}
                </View>
                <AtButton type='' className='bottonBtn' >返回个人中心</AtButton>
            </View>
        )
    }
}